home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / asm / utils / extermshell / extermshell.s < prev    next >
Text File  |  1980-01-03  |  12KB  |  300 lines

  1.  
  2.         include    gst:OS3_GST.i        * all OS3 includes in 1 file *
  3.  
  4. ;        INCLUDE exec/exec.i
  5. ;        INCLUDE libraries/exec_lib.i
  6. ;        INCLUDE intuition/intuition.i
  7. ;        INCLUDE libraries/intuition_lib.i
  8. ;        INCLUDE devices/serial.i
  9. ;        INCLUDE devices/console.i
  10.  
  11. SerBuf        =    128    ; Serial incoming buffer in bytes
  12.  
  13.         RSRESET
  14. ConWritePort    rs.l    1    ; Console Write Port
  15. ConWriteReq    rs.l    1    ; Console Write Request
  16. ConReadPort    rs.l    1    ; Console Read Port
  17. ConReadReq    rs.l    1    ; Console Read Request
  18. ConsoleBit    rs.w    1    ; Console Signal Bits 
  19.  
  20. SerWritePort    rs.l    1    ; Serial Write Port
  21. SerWriteReq    rs.l    1    ; Serial Write Request
  22. SerReadPort    rs.l    1    ; Serial Read Port
  23. SerReadReq    rs.l    1    ; Serial Read Request
  24. SerialBit    rs.w    1    ; Serial Signal Bits
  25.  
  26. _IntuitionBase    rs.l    1    ; Intuition Base
  27. WindowPtr    rs.l    1    ; Window Base
  28. WaitState    rs.l    1    ; State of the sigbits after a wait
  29. WindowBit    rs.w    1    ; SigBit for the window
  30. conbuffer    rs.w    1    ; buffer for the important stuff
  31.  
  32. serbuffer    rs.b    SerBuf
  33.  
  34. GT_VarLength    rs.l    1
  35.  
  36.         RSRESET
  37. WritePort    rs.l    1   ; Location of the write port
  38. WriteReq    rs.l    1   ; Location of the write request
  39. ReadPort    rs.l    1   ; Location of the read port
  40. ReadReq     rs.l    1   ; Location of the read request
  41. SignalBit    rs.w    1   ; Location of the SigBit
  42.  
  43.  
  44. GT        link    a5,#-(GT_VarLength)     ; Get the global variable memory.
  45.         lea    -(GT_VarLength)(a5),a5    ; give us some varmem please!
  46.  
  47. *-------------- Open intuition library
  48.  
  49.         movea.l 4.w,a6            ; Load ExecBase in a6
  50.         lea    IntuiName(pc),a1    ; Put the Intuition name in a1
  51.         jsr    _LVOOldOpenLibrary(a6)    ; Open it.
  52.         move.l    d0,_IntuitionBase(a5)   ; Move the base pointer into the global var.
  53.         beq.w    KillMem         ; If not free mem.
  54.  
  55. *-------------- Open Term Window..
  56.  
  57.         movea.l d0,a6
  58.         suba.l    a0,a0            ; Quickly put a 0 into a0
  59.         lea    windowtags(pc),a1    ; Put the window tags into a1
  60.         jsr    _LVOOpenWindowTagList(a6) ; Open the window.
  61.         move.l    d0,WindowPtr(a5)        ; Store the window ptr into global var.
  62.         beq.w    KillLib         ; If not close lib.
  63.  
  64.         move.l    d0,a0            ; Put window ptr into a0
  65.         move.l    wd_UserPort(a0),a1      ; Put UserPort into a1
  66.         move.b    MP_SIGBIT(a1),WindowBit(a5) ; Store window's sigbit in global va
  67.  
  68. *-------------- Allocate a Console IO..
  69.  
  70.         movea.l 4.w,a6            ; Load ExecBase back in a6
  71.         moveq    #IOSTD_SIZE,d4        ; Push the size of the requests we need
  72.         lea    ConWritePort(a5),a4    ; Push the beginning of the data structure
  73.         bsr.w    AllocPorts        ; Call the handy AllocPorts command
  74.         tst.l    d0            ; Test and see if everything opened
  75.         beq.w    KillWindow        ; If not close the window
  76.  
  77.         movea.l ConWriteReq(a5),a1      ; Move the write request into a1
  78.         move.l    WindowPtr(a5),IO_DATA(a1) ; Shove the window ptr into io_data
  79.         move.l    #wd_Size,IO_LENGTH(a1)  ; Put the window size into length
  80.  
  81. *-------------- Open Console Device..
  82.  
  83.         moveq    #0,d0            ; This is the con unit number
  84.         move.l    d0,d1            ; clear out d1
  85.         lea    ConName(pc),a0        ; Load the console name into a0
  86.         jsr    _LVOOpenDevice(a6)      ; Open it
  87.         tst.l    d0            ; See if it was opened
  88.         bne.w    KillConPorts        ; If not kill the ports
  89.  
  90.         move.l    ConWriteReq(a5),a0      ; Move write request into a0
  91.         move.l    ConReadReq(a5),a1       ; Move read request into a1
  92.         move.l    IO_DEVICE(a0),IO_DEVICE(a1) ; Copy the IO_DEVICE and the IO_UNIT
  93.         move.l    IO_UNIT(a0),IO_UNIT(a1) ; From the write request to the read request
  94.  
  95. *-------------- Allocate a Serial IO
  96.  
  97.         moveq    #IOEXTSER_SIZE,d4    ; d4=serial request size
  98.         lea    SerWritePort(a5),a4    ; beginning of the data structure
  99.         bsr.w    AllocPorts        ; Get the ports
  100.         tst.l    d0            ; See if it all opened
  101.         beq.w    CloseConsole        ; If not close the console
  102.  
  103. *-------------- Open Serial Device..
  104.  
  105.         move.l    SerWriteReq(a5),a1      ; Move the write request into a1
  106.         move.b    #SERF_SHARED,IO_SERFLAGS(a1) ; Set the flags
  107.         moveq    #0,d0            ; Unit 0
  108.         move.l    d0,d1            ; No flags
  109.         lea    SerName(pc),a0        ; Put the ser name into a0
  110.         jsr    _LVOOpenDevice(a6)      ; Open the device
  111.         tst.l    d0            ; See if it opened
  112.         bne.w    KillSerPorts        ; If not kill the ports
  113.  
  114.         move.l    SerWriteReq(a5),a0      ; Move the write request into a0
  115.         move.l    SerReadReq(a5),a1       ; Move the read  request into a1
  116.         move.l    IO_DEVICE(a0),IO_DEVICE(a1) ; Copy IO_DEVICE and IO_UNIT
  117.         move.l    IO_UNIT(a0),IO_UNIT(a1) ; from the write request into the read request
  118.  
  119.         bsr.w    ConGet            ; Send out a read request for the console.
  120.         bsr.w    SerGet            ; Send out a read request for the serial port.
  121.  
  122. Mainloop:    moveq    #0,d0            ; Clear out d0.
  123.         move.b    WindowBit(a5),d1        ; Put window's sigbit into d1.
  124.         bset.l    d1,d0            ; Set it in d0.
  125.         move.b    ConsoleBit(a5),d1       ; Put console's sigbit into d1.
  126.         bset.l    d1,d0            ; Set it in d0.
  127.         move.b    SerialBit(a5),d1        ; Put serial's sigbit into d1.
  128.         bset.l    d1,d0            ; Set it in d0.
  129.         jsr    _LVOWait(a6)            ; Wait for any of the sigbits.
  130.         move.l    d0,WaitState(a5)        ; Save the sigbits that woke us up in a global var.
  131.  
  132.         move.b    ConsoleBit(a5),d1       ; Put console's sigbit in d1.
  133.         btst.l    d1,d0            ; See if it is one of the bits that woke us.
  134.         beq.b    ntest            ; If not go to next test.
  135.         move.l    SerWriteReq(a5),a1      ; Move the serial write request into a1
  136.         move.w    #CMD_WRITE,IO_COMMAND(a1) ; Prepare to write
  137.         lea    conbuffer(a5),a0        ; Load the conbuffer into the data
  138.         move.l    a0,IO_DATA(a1)          ; Load its length into the length
  139.         moveq    #1,d0
  140.         move.l    d0,IO_LENGTH(a1)
  141.         jsr    _LVODoIO(a6)            ; Write it
  142.         bsr.w    ConGet            ; Send out the console read request again
  143.  
  144. ntest:        move.l    WaitState(a5),d0        ; Load the wakeup bits again
  145.         move.b    SerialBit(a5),d1        ; Put the serial sigbit into d1
  146.         btst.l    d1,d0            ; See if we have the ser bit
  147.         beq.b    .2            ; If not go to .2
  148.         move.l    ConWriteReq(a5),a1      ; Else put the console write request into a1
  149.         move.w    #CMD_WRITE,IO_COMMAND(a1) ; Prepare to write
  150.         lea    serbuffer(a5),a0        ; Load the serbuffer as the data
  151.         move.l    a0,IO_DATA(a1)
  152.         moveq    #-1,d0
  153.         move.l    d0,IO_LENGTH(a1)       ; Set length for a null terminated string
  154.         jsr    _LVODoIO(a6)            ; Write it
  155.         bsr.w    SerGet            ; Send out the serial read request again
  156.  
  157. .2        move.l    WaitState(a5),d0        ; Load the wakeup bits yet again
  158.         move.b    WindowBit(a5),d1        ; Load the window's sigbit into d1
  159.         btst.l    d1,d0            ; See if we got a close gadget hit
  160.         beq.b    Mainloop        ; If not loop again
  161.  
  162. _Close        movea.l SerReadReq(a5),a1       ; Load the serial read request into a1
  163.         jsr    _LVOCheckIO(a6)         ; See if it's still out
  164.         tst.l    d0
  165.         bne.b    .1            ; If not jump to .1
  166.         movea.l SerReadReq(a5),a1       ; Load the read request again
  167.         jsr    _LVOAbortIO(a6)         ; Abort it
  168.         movea.l SerReadReq(a5),a1       ; Load the read request again
  169.         jsr    _LVOWaitIO(a6)          ; Wait for it to be aborted
  170.  
  171. .1        movea.l SerWriteReq(a5),a1      ; Load the write request into a1
  172.         jsr    _LVOCloseDevice(a6)     ; Close the serial port
  173.  
  174. KillSerPorts:    lea    SerWritePort(a5),a4    ; Push the begining of the data structure
  175.         bsr.w    FreePorts        ; Free the ports
  176.  
  177. CloseConsole:    movea.l ConReadReq(a5),a1       ; Load the console write port into a1
  178.         jsr    _LVOCheckIO(a6)         ; See if it's still out
  179.         tst.l    d0
  180.         bne.b    .1            ; If not jump to .1
  181.         movea.l ConReadReq(a5),a1       ; Load the read request again
  182.         jsr    _LVOAbortIO(a6)         ; Abort the request
  183.         movea.l ConReadReq(a5),a1       ; Load the read request again
  184.         jsr    _LVOWaitIO(a6)          ; Wait for it to be aborted
  185.  
  186. .1        movea.l ConWriteReq(a5),a1      ; Load the write request into a1
  187.         jsr    _LVOCloseDevice(a6)     ; Close the console
  188.  
  189. KillConPorts    lea    ConWritePort(a5),a4    ; begining of the data structure
  190.         bsr.b    FreePorts        ; Free the ports
  191.  
  192. *-------------- Close Term Window
  193.  
  194. KillWindow:    move.l    WindowPtr(a5),a0        ; Move the window ptr into a0
  195.         movea.l _IntuitionBase(a5),a6   ; Load IntuitionBase into a6
  196.         jsr    _LVOCloseWindow(a6)     ; Close the window
  197.  
  198. *-------------- Close Intuition Library
  199.  
  200. KillLib        move.l    _IntuitionBase(a5),a1   ; Move IntuitionBase into a1
  201.         movea.l 4.w,a6            ; Load ExecBase into a6
  202.         jsr    _LVOCloseLibrary(a6)    ; Close Intuition
  203.  
  204. *-------------- Free RS Area
  205.  
  206. KillMem        lea    (GT_VarLength)(a5),a5    ; Add our global variable length to a5
  207.         unlk    a5            ; Free our global variables
  208.         moveq    #0,d0            ; This returns "no errors" to AmigaDOS
  209. ending        rts                ; Return
  210.  
  211.  
  212.  
  213. ; AllocPorts ( baseaddr, size )
  214.  
  215. AllocPorts    jsr    _LVOCreateMsgPort(a6)   ; Create a msg port
  216.         move.l    d0,WritePort(a4)        ; Save it in the write port
  217.         beq.b    PortsEnding        ; If we didn't get it then end
  218.  
  219.         movea.l d0,a0            ; Move the port into a0
  220.         move.l    d4,d0            ; Move the size into d0
  221.         jsr    _LVOCreateIORequest(a6) ; Create an I/O Request
  222.         move.l    d0,WriteReq(a4)         ; Save it's addr
  223.         beq.b    FreeWritePort        ; If we didn't get it then free the write port
  224.  
  225.         jsr    _LVOCreateMsgPort(a6)   ; Create a read port
  226.         move.l    d0,ReadPort(a4)         ; Save it's addr
  227.         beq.b    FreeWriteReq        ; If we didn't get it then free the write req
  228.         movea.l d0,a0            ; Move the port into a0
  229.         move.b    MP_SIGBIT(a0),SignalBit(a4) ; Save it's sigbit
  230.  
  231.         move.l    d4,d0            ; Move the size into d0
  232.         jsr    _LVOCreateIORequest(a6) ; Create a read request
  233.         move.l    d0,ReadReq(a4)          ; Save it's addr
  234.         beq.b    FreeReadPort        ; If we didn't get it free the read port
  235.         moveq    #1,d0            ; Put a 1 in d0 to show we opened everything
  236.         rts
  237.  
  238. FreePorts:    move.l    ReadReq(a4),a0          ; Move the read request into a0
  239.         jsr    _LVODeleteIORequest(a6) ; Delete it
  240. FreeReadPort:    move.l    ReadPort(a4),a0         ; Move the read port into a0
  241.         jsr    _LVODeleteMsgPort(a6)   ; Delete it
  242. FreeWriteReq:    move.l    WriteReq(a4),a0         ; Move the write request into a0
  243.         jsr    _LVODeleteIORequest(a6) ; Delete it
  244. FreeWritePort:    move.l    WritePort(a4),a0        ; Move the write port into a0
  245.         jsr    _LVODeleteMsgPort(a6)   ; Delete it
  246. PortsEnding:    moveq    #0,d0            ; Clear d0 to indicate Alloc ports failed
  247.         rts
  248.  
  249.  
  250. SerGet        lea    serbuffer(a5),a0        ; Load address of serbuffer into a0
  251.         moveq    #SerBuf-1,d0        ; Just a quick routine to clear
  252. cls:        sf.b    (a0)+               ; the serial buffer
  253.         dbf    d0,cls
  254.  
  255.         move.l    SerReadPort(a5),a0      ; Move the address of the ReadPort into a0
  256.         jsr    _LVOGetMsg(a6)          ; Get the message in the port.
  257.  
  258.         move.l    SerWriteReq(a5),a1      ; Move our write request into a1
  259.         move.w    #SDCMD_QUERY,IO_COMMAND(a1) ; Get it ready for a querry
  260.         jsr    _LVODoIO(a6)            ; Do it.
  261.         move.l    SerWriteReq(a5),a0      ; Load the write request into a0
  262.         move.l    IO_ACTUAL(a0),d0        ; Put the number of chars got into d0
  263.         bne.b    .1            ; Jump to .1 if it's not zero
  264.         moveq    #1,d1            ; Ask for 1 char
  265.         bra.s    send_it            ; Jump to .3    
  266.  
  267. .1        moveq    #SerBuf-1,d2        ; Else move the buffer size into d1
  268.         cmp.l    d2,d0            ; Compare the number to the size of the buffer
  269.         ble.s    num_ch            ; If chars waiting is greater than the buffer then jump to .2
  270.         move.l    d2,d1
  271.         bra.s    send_it            ; Jump to .3
  272.  
  273. num_ch:        move.l    d0,d1            ; Move the number of chars waiting into d1
  274. send_it:    move.l    SerReadReq(a5),a1       ; Put the read request into a1
  275.         lea    serbuffer(a5),a0        ; Load the address of the buffer into a0
  276. send:        move.w    #CMD_READ,IO_COMMAND(a1) ; Prepare to read
  277.         move.l    a0,IO_DATA(a1)
  278.         move.l    d1,IO_LENGTH(a1)        ; Load 1 as the length
  279.         jmp    _LVOSendIO(a6)          ; Send it out
  280.  
  281. ConGet:        movea.l ConReadPort(a5),a0      ; Move the read port into a0
  282.         jsr    _LVOGetMsg(a6)          ; Get the message in it
  283.         movea.l ConReadReq(a5),a1       ; Move the read request into a1
  284.         lea    conbuffer(a5),a0    ; Load the conbuffer into the data
  285.         moveq    #1,d1
  286.         bra.s    send
  287.  
  288. windowtags:    dc.l    WA_Left,0
  289.         dc.l    WA_Top,11
  290.         dc.l    WA_Width,640
  291.         dc.l    WA_Height,256-11
  292.         dc.l    WA_IDCMP,IDCMP_CLOSEWINDOW
  293.         dc.l    WA_Flags,WFLG_DRAGBAR!WFLG_DEPTHGADGET!WFLG_CLOSEGADGET!WFLG_ACTIVATE!WFLG_SIMPLE_REFRESH
  294.         dc.l    TAG_DONE
  295.  
  296. IntuiName    dc.b    'intuition.library',0
  297. SerName        dc.b    'serial.device',0
  298. ConName        dc.b    'console.device',0
  299.         END
  300.